﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NesEmulatorX._6052OpCodes
{
	public class ADC_Absolute : CPU6502OpCode
	{
		#region Properties

		public override int Bytes
		{
			get { return 3; }
		}

		public override int Cycles
		{
			get { return 4; }
		}

		#endregion

		#region Public Methods

		public override void Action(CPU6502 cpu, CPUMemory memory, byte[] bytes)
		{
			uint address = (uint)(bytes[0] << 8) | bytes[1];

			int i = cpu.A + memory.Memory[address];
			i += cpu.GetCarryFlag() ? 1 : 0;

			cpu.SetOverflowFlag(i);

			cpu.A = (byte)(i & 0xFF);

			cpu.SetCarryFlag(cpu.A);
			cpu.SetZeroFlag(cpu.A);
		}

		public override string Decode(CPU6502 cpu, CPUMemory memory, byte[] bytes)
		{
			return String.Format("ADC ${1:X}{0:X}", bytes[0], bytes[1]);
		}

		#endregion
	}
}
